{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "6vddxASQcwOx"
   },
   "source": [
    "# Functions\n",
    "\n",
    "Functions are blocks of code that can be used over and over again to perform a specific action.\n",
    "\n",
    "As we know, in Python, there are print (), len () etc. Many available functions are defined.\n",
    "\n",
    "We can use it in our own code by providing access to functions defined in libraries, modules and packages. These are called predefined functions, embedded functions (built-in) or library functions. We can use ready-made functions as well as create our own functions. (User-defined)\n",
    "\n",
    "\n",
    "Functions prevent code repetition and our code stays more modular and organized.\n",
    "\n",
    "\n",
    "*****\n",
    "\n",
    "def \"function_name\"(parameter1,parameter2,..):\n",
    "\n",
    "\n",
    "> \"Do something\"\n",
    "\n",
    "  return \"return something\"  (depends on functionality) \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "xmv4r_jCboXC"
   },
   "outputs": [],
   "source": [
    "def hello():\n",
    "  print(\"Hello Everyone!!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "9WyymUQqgSBQ"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Everyone!!\n"
     ]
    }
   ],
   "source": [
    "hello()   #calling the func   #the functions don't have any parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "0mNT-X0DoP7y"
   },
   "outputs": [],
   "source": [
    "def hello(name):\n",
    "  print(\"Hello \" + name)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "DxZKzFIuoW08"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Asli\n"
     ]
    }
   ],
   "source": [
    "hello(\"Asli\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def func_in_func(name1):\n",
    "    return hello(name1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Ugurcan\n"
     ]
    }
   ],
   "source": [
    "func_in_func(\"Ugurcan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "3AoI1i0igZC7",
    "outputId": "96d5c07a-fb7e-4965-b107-d7e3419b4e3d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World!!\n",
      "Google\n",
      "Hello World!!\n",
      "Hello World!!\n",
      "Hello World!!\n",
      "Hello World!!\n"
     ]
    }
   ],
   "source": [
    "def func1():\n",
    "  print(\"Hello World!!\")\n",
    "\n",
    "\n",
    "func1()\n",
    "print(\"Google\")\n",
    "func1()\n",
    "func1()\n",
    "func1()\n",
    "func1()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "iiSPTWt3hJHo"
   },
   "outputs": [],
   "source": [
    "def summ(a,b):\n",
    "  summ = a + b\n",
    "  print(summ)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "WNgM1TR4haRG"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13.5\n"
     ]
    }
   ],
   "source": [
    "summ(6.0,7.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 52
    },
    "colab_type": "code",
    "id": "MfnQx9FFhd5H",
    "outputId": "ef0339f9-f195-40fb-cad8-a3c231726c26"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17\n"
     ]
    }
   ],
   "source": [
    "t = summ(8,9)\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "NiymGvuihkZ2"
   },
   "outputs": [],
   "source": [
    "def func(x,y):\n",
    "  summ = x + y\n",
    "  multip = x * y\n",
    "  return (summ,multip)\n",
    "\n",
    "#t = summ \n",
    "#c = multip\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "SbtW4TLdh7Pp",
    "outputId": "b2dd6bb7-6769-4d82-96ee-d622de955917"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "68 1035\n"
     ]
    }
   ],
   "source": [
    "t,c = func(23,45)\n",
    "\n",
    "print(t,c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(68, 1035)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "func(23,45)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Nca_Rpf9iC-x"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sum of the values: 68, Multiplying of the values: 1035\n"
     ]
    }
   ],
   "source": [
    "print(\"Sum of the values: \" + str(t) + \", Multiplying of the values: \" + str(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "5IS0ARTJiPY1"
   },
   "outputs": [],
   "source": [
    "#Let's write a function that it will square the entered number, but will be terminated when you enter the number 5 and give us an error message.\n",
    "\n",
    "\n",
    "def sqr(x):\n",
    "  if x == 5:\n",
    "    return (\"Terminated because you entered 5\")\n",
    "\n",
    "  result = x **2\n",
    "  return (result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "w0Am5qkekKNH",
    "outputId": "3a1be730-2c76-47b4-a44f-87f746392359"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sqr(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "-A1MrkLDkMju"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Terminated because you entered 5'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sqr(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "gsu2kbuJnKmx"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Terminated because you entered 5\n"
     ]
    }
   ],
   "source": [
    "d = sqr(5)\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "ewtG6xuRkQsy"
   },
   "outputs": [],
   "source": [
    "# Let's write a function that tells you whether the entered number is positive, negative or zero.\n",
    "\n",
    "\n",
    "\n",
    "def func(x):\n",
    "  if x > 0:\n",
    "    return (\"Positive\")\n",
    "  elif x < 0:\n",
    "    return (\"Negative\")\n",
    "  else:\n",
    "    return (\"Zero\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "UQ3T_8UTlJ8u"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Negative\n",
      "Positive\n",
      "Positive\n",
      "Zero\n",
      "Negative\n",
      "Negative\n"
     ]
    }
   ],
   "source": [
    "for i in [-2,5,6,0,-4,-7]:\n",
    "  print(func(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "_gih-r9xlZBr"
   },
   "outputs": [],
   "source": [
    "#factorial calculation\n",
    "#0! = 1\n",
    "#1!= 1\n",
    "#2!= 2 * 1 =2\n",
    "#6! = 6 * 5* 4 *3 * 2 *1 = 720\n",
    "\n",
    "\n",
    "def factorial(num):\n",
    "  factorial = 1\n",
    "  if (num == 0 or num == 1):\n",
    "    print(\"Factorial: \", factorial)\n",
    "  else:\n",
    "    while (num >= 1):\n",
    "      factorial = factorial * num\n",
    "      num -= 1\n",
    "    print(\"Factorial: \", factorial)\n",
    "\n",
    "\n",
    "# 1 * 5 = 5 = factorial\n",
    "# 5 * 4 = 20\n",
    "# 20 * 3 = 60\n",
    "#60 * 2 = 120\n",
    "# 120 * 1 = 120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "T5ykiNt_yeck"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Factorial:  120\n"
     ]
    }
   ],
   "source": [
    "factorial(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "def faktoriyel(sayi):\n",
    "  faktoriyel = 1\n",
    "  for i in range(1,sayi+1):\n",
    "    faktoriyel *= i\n",
    "  return faktoriyel\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "120"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "faktoriyel(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "OQBMccOwyhl9"
   },
   "outputs": [],
   "source": [
    "#using for loop\n",
    "\n",
    "def factorial2(num2):\n",
    "  factorial2 = 1\n",
    "  if (num2 == 0 or num2 == 1):\n",
    "    print(\"Factorial: \", factorial2)\n",
    "  else:\n",
    "    for i in range(factorial2, num2+1):    \n",
    "        factorial2 *= i      \n",
    "    print(\"Factorial: \", factorial2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "3e4oPm5yy3Co"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Factorial:  720\n"
     ]
    }
   ],
   "source": [
    "factorial2(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "blFFawxml7wW"
   },
   "outputs": [],
   "source": [
    "def factorial3(nums):\n",
    "  factorial3 = 1\n",
    "  if (nums == 0 or nums == 1):\n",
    "    return (\"Factorial: \", factorial3)\n",
    "  else:\n",
    "    for i in range(factorial3, nums+1):\n",
    "       factorial3 *= i      \n",
    "    return (factorial3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "HVWS7rb9mAIf"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "720\n"
     ]
    }
   ],
   "source": [
    "x = factorial3(6)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "720"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "HIUms-AlzQu9"
   },
   "outputs": [],
   "source": [
    "def hello2(name, capLetter = False):\n",
    "  if capLetter:\n",
    "    print(\"Hello \" + name.upper())\n",
    "  else:\n",
    "    print(\"Hello \" + name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "DkHm9Vtw0O4M"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello asli\n"
     ]
    }
   ],
   "source": [
    "hello2(\"asli\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "dYyDrfTn0TOS"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello ASLI\n"
     ]
    }
   ],
   "source": [
    "hello2(\"Asli\", capLetter= True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#lambda function\n",
    "(lambda x: x + 1)(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Full name: Guido Van Rossum'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "full_name = lambda first, last: f'Full name: {first.title()} {last.title()}'\n",
    "full_name('guido', 'van rossum')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### * args and   ** kwargs\n",
    "* args (Non Keyword Arguments)\n",
    "* kwargs (Keyword Arguments)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "AzJDy8xD1Rbm"
   },
   "outputs": [],
   "source": [
    "def multp(*args):\n",
    "  result = 1\n",
    "  for i in args:\n",
    "        result *= i\n",
    "        print(result) \n",
    "\n",
    "# *args keeps the data as tuple type."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "crk-VWf912z_",
    "outputId": "251acfa4-5dcc-44fc-ff37-89e125cab82e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "20\n",
      "120\n",
      "840\n",
      "6720\n",
      "60480\n"
     ]
    }
   ],
   "source": [
    "multp(4,5,6,7,8,9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def multp1(*args):\n",
    "  result = 2\n",
    "  for i in args:\n",
    "        result *= i # result = result * i\n",
    "        print(result) \n",
    "\n",
    "\n",
    "# *args keeps the data as tuple type."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 5, 6, 7, 4, 5, 6, 7]\n"
     ]
    }
   ],
   "source": [
    "multp1([4,5,6,7])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "sp9bJPmu1-lF",
    "outputId": "0aab548b-3a1f-4c19-ddfe-8287e43ee2f6"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "12\n",
      "48\n",
      "240\n"
     ]
    }
   ],
   "source": [
    "multp1(2,3,4,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 5, 6, 4, 5, 6, 4, 5, 6]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[4,5,6] * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'Murat', 'name2': 'Ömer', 'number': 12345, 'can': 'Emir', 'beril': 'yılmaz'}\n"
     ]
    }
   ],
   "source": [
    "def func_kwargs(**kwargs):\n",
    "    print(kwargs)\n",
    "    \n",
    "func_kwargs(name = \"Murat\", name2 = \"Ömer\", number=12345, can='Emir', beril='yılmaz')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "M_gEN02J7Z6P"
   },
   "outputs": [],
   "source": [
    "def salaryCalc(salary):\n",
    "\n",
    "  if salary < 0:\n",
    "    return(\"Invalid value\")\n",
    "  else:\n",
    "    if 0 < salary <= 1000:\n",
    "      salary = salary + salary * 0.15\n",
    "    elif salary <= 2000:\n",
    "      salary = salary + salary * 0.1\n",
    "    elif salary <= 3000:\n",
    "      salary = salary + salary * 0.05\n",
    "    else:\n",
    "      salary = salary + salary * 0.025\n",
    "\n",
    "    return (\"New salary: \", salary)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Tp8kE5iH7-_x"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Invalid value'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "salaryCalc(-5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('New salary: ', 920.0)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "salaryCalc(800)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "I9BT87fl-Kgr"
   },
   "outputs": [],
   "source": [
    "\n",
    "def salaryCalc2():\n",
    "\n",
    "  salary = float(input(\"Please enter your current salary: \"))\n",
    "\n",
    "  if salary < 0:\n",
    "    return(\"Invalid value\")\n",
    "  else:\n",
    "    if 0 < salary <= 1000:\n",
    "      salary = salary + salary * 0.15\n",
    "    elif salary <= 2000:\n",
    "      salary = salary + salary * 0.1\n",
    "    elif salary <= 3000:\n",
    "      salary = salary + salary * 0.05\n",
    "    else:\n",
    "      salary = salary + salary * 0.025\n",
    "\n",
    "    return (\"New salary: \", salary)\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "bF1ty6Cc8U_X"
   },
   "outputs": [],
   "source": [
    "new_salary = salaryCalc2() \n",
    "print(new_salary)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "6sOO_4CbBygM"
   },
   "source": [
    "### Let's write a function that returns a random word from a list.\n",
    "\n",
    "### Modules\n",
    "\n",
    "import numpy\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "import myModules\n",
    "\n",
    "myModules.myFunc()\n",
    "\n",
    "from myModules import *\n",
    "\n",
    "myFunc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "fyf2VtDZ3ALS"
   },
   "outputs": [],
   "source": [
    "words = [\"artificial\",\"intelligence\",\"machine\",\"learning\",\"python\",\"programming\"]\n",
    "\n",
    "\n",
    "#from random import *\n",
    "import random as rnd\n",
    "\n",
    "def randomWord(words):\n",
    "  index = rnd.randint(0, len(words)-1)\n",
    "  return words[index]\n",
    "  \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "vdt230OzC_DR",
    "outputId": "d86a979d-f371-44b4-9769-3b074686680c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "python\n"
     ]
    }
   ],
   "source": [
    "word = randomWord(words)\n",
    "print(word)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "MfFOsrA6AfmC"
   },
   "source": [
    "### Global & Local Variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "7_UD1zAn_lxX",
    "outputId": "943b58cd-497e-4cec-962f-37084451f85a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "x = 5\n",
    "\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "IisEjgqpAqCi"
   },
   "outputs": [],
   "source": [
    "def display():\n",
    "  x = 4\n",
    "  return(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "6dhEuYDjAylB",
    "outputId": "3d88f156-bdd1-411b-9fcb-93715c02d292"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "display()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "dPUxfagJA7Gn",
    "outputId": "ba6bf99f-ba77-4498-b6f5-fe4c2328d920"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "WJreHgrGllCV"
   },
   "source": [
    "## Methods\n",
    "\n",
    "Functions are called by name, it can take parameters inside and optionally the resulting value can be used outside of the function.\n",
    "\n",
    "\n",
    "Methods are also called by name, in many ways they are like functions, but calling is performed through an object such as a String or list.\n",
    "\n",
    "\n",
    "object.methodName(parameter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "G56qfrjqDEDP"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Please enter a name: kübra\n",
      "KÜBRA\n"
     ]
    }
   ],
   "source": [
    "s = input(\"Please enter a name: \")\n",
    "\n",
    "\n",
    "print(s.upper())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 5, 6]"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#it does not return any value\n",
    "list1 = [1,2,3,4,5,6]\n",
    "\n",
    "list1.remove(4)\n",
    "list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 5, 6]"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list1.index(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "7DzoBNeApbzZ",
    "outputId": "1574c1d7-156b-4650-f3b6-8a2b22b98eed"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "#return the index of the element with the highest value in a given list.\n",
    "\n",
    "myList = [45,7,23,6,12,78]\n",
    "\n",
    "maxElement = max(myList)\n",
    "\n",
    "maxIndex = myList.index(maxElement)\n",
    "\n",
    "print(maxIndex)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "Day_5.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
